﻿Imports Pronama.Sekatyaku.Model
Imports Pronama.Sekatyaku.ViewModel
Imports System.Collections.ObjectModel

Public Class SettingsWindow

    Private _Comments As New Dictionary(Of BroadcastCommentKind, BroadcastComment)
    Public ReadOnly Property Comments As IDictionary(Of BroadcastCommentKind, BroadcastComment)
        Get
            Return _Comments
        End Get
    End Property

    Property PlayKind As PlayKind = Sekatyaku.PlayKind.Play


    Private _SecondsBeforeStart As Integer = 30
    Public Property SecondsBeforeStart() As Integer
        Get
            Return _SecondsBeforeStart
        End Get
        Set(ByVal value As Integer)
            If value < SecondsBeforeStartSlider.Minimum OrElse
               SecondsBeforeStartSlider.Maximum < value Then
                Exit Property
            End If
            _SecondsBeforeStart = value
        End Set
    End Property

    Private _SecondsBeforeEnd As Integer = 25
    Public Property SecondsBeforeEnd() As Integer
        Get
            Return _SecondsBeforeEnd
        End Get
        Set(ByVal value As Integer)
            If value < SecondsBeforeEndSlider.Minimum OrElse
               SecondsBeforeEndSlider.Maximum < value Then
                Exit Property
            End If
            _SecondsBeforeEnd = value
        End Set
    End Property

    Public Sub New()

        ' この呼び出しはデザイナーで必要です。
        InitializeComponent()

        ' InitializeComponent() 呼び出しの後で初期化を追加します。

        InitializeComments()
        InitializeKind()
    End Sub

    Private Sub InitializeComments()

        Comments.Add(BroadcastCommentKind.Opening, New BroadcastComment)
        Comments.Add(BroadcastCommentKind.VideoInfo, New BroadcastComment)
        Comments.Add(BroadcastCommentKind.VotingStartCountDown, New BroadcastComment)
        Comments.Add(BroadcastCommentKind.VotingStarted, New BroadcastComment)
        Comments.Add(BroadcastCommentKind.VotingEndCountDown, New BroadcastComment)
        Comments.Add(BroadcastCommentKind.VotingEnded, New BroadcastComment)

        Dim viewModels = New ObservableCollection(Of BroadcastCommentViewModel)
        viewModels.Add(New BroadcastCommentViewModel(Comments(BroadcastCommentKind.Opening)) With {.Title = "オープニング",
                                                                      .Description = ""})
        viewModels.Add(New BroadcastCommentViewModel(Comments(BroadcastCommentKind.VideoInfo)) With {.Title = "動画情報",
                                                                      .Description = "{date}, {title}, {desc} がそれぞれ動画の投稿日時、タイトル、説明に置き換わります。"})
        viewModels.Add(New BroadcastCommentViewModel(Comments(BroadcastCommentKind.VotingStartCountDown)) With {.Title = "延長アンケート開始カウントダウン",
                                                                      .Description = "{sec}が秒数に置き換わります。"})
        viewModels.Add(New BroadcastCommentViewModel(Comments(BroadcastCommentKind.VotingStarted)) With {.Title = "延長アンケート開始",
                                                                      .Description = ""})
        viewModels.Add(New BroadcastCommentViewModel(Comments(BroadcastCommentKind.VotingEndCountDown)) With {.Title = "延長アンケート終了カウントダウン",
                                                                      .Description = "{sec}が秒数に置き換わります。"})
        'viewModels.Add(New BroadcastCommentViewModel(Comments(BroadcastCommentKind.VotingEnded)) With {.Title = "延長アンケート終了",
        '                                                              .Description = ""})

        CommentsItemsControl.ItemsSource = viewModels
    End Sub

    Private Sub InitializeKind()

        Dim dic = New Dictionary(Of PlayKind, String)
        dic.Add(PlayKind.Play, "/play")
        dic.Add(PlayKind.PlaySub, "/play sub")
        dic.Add(PlayKind.PlaySound, "/playsound")
        dic.Add(PlayKind.PlaySoundSub, "/playsound sub")

        PlayKindComboBox.ItemsSource = dic

        SecondsBeforeStartSlider.Value = SecondsBeforeStart
        SecondsBeforeEndSlider.Value = SecondsBeforeEnd

    End Sub

    Private Sub OkButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Me.DialogResult = True
        Try
            Me.PlayKind = DirectCast(PlayKindComboBox.SelectedValue, PlayKind)
            Me.SecondsBeforeStart = Convert.ToInt32(SecondsBeforeStartSlider.Value)
            Me.SecondsBeforeEnd = Convert.ToInt32(SecondsBeforeEndSlider.Value)

        Catch ex As Exception
        End Try
        Me.Close()
    End Sub

    Private Sub Cansel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Me.DialogResult = False
        Me.Close()
    End Sub

    Private Sub SettingsWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        PlayKindComboBox.SelectedValue = Me.PlayKind
        Me.MoveToCenter()
    End Sub

End Class
